#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=60000;

class City {
public:
  int x, y, z, id;
};

void sort(City *a, int l, int r) {
  int i=l, j=r, mid=a[(l+r)/2].z;
  City temp;
  for (; i<=j; ) {
    for (; a[j].z>mid; j--);
    for (; a[i].z<mid; i++);
    if (i<=j) {
      temp=a[i], a[i]=a[j], a[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    sort(a, i, r);
  }
  if (j>l) {
    sort(a, l, j);
  }
}

void swap(int &a, int &b) {
  int t;
  t=a, a=b, b=t;
}

int main() {
#ifdef DEBUG
  freopen("0.in", "r", stdin);
  freopen("0.out", "w", stdout);
#endif

  static City city[maxn+1];
  static int map[maxn+1];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=n; i++) {
    scanf("%d %d %d", &city[i].x, &city[i].y, &city[i].z);
    city[i].id = i-1;
  }
  sort(city, 1, n);
  for (int i=1; i<=n; i++) {
    map[city[i].id] = i;
  }

  char type[6];
  for (int i=1; i<=m; i++) {
    scanf(" %s", type);
    if (type[0]=='Q') {
      int x0, y0, x1, y1, k;
      scanf("%d %d %d %d %d", &x0, &y0, &x1, &y1, &k);
      if (x0>x1) {
	swap(x0, x1);
      }
      if (y0>y1) {
	swap(y0, y1);
      }

      int j;
      for (j=1; j<=n; j++) {
	if (city[j].x>=x0 && city[j].x<=x1 && city[j].y>=y0 && city[j].y<=y1) {
	  k--;
	}
	if (!k) {
	  break;
	}
      }
      if (k) {
	printf("It doesn't exist.\n");
      } else {
	printf("%d\n", city[j].z);
      }
    } else {
      int x, y;
      scanf("%d %d", &x, &y);
      swap(city[map[x]].x, city[map[y]].x);
      swap(city[map[x]].y, city[map[y]].y);
      swap(city[map[x]].id, city[map[y]].id);
      swap(map[x], map[y]);
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
